package com.example.mydemo.utils;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class WebDriverUtils {

    private  static String chromebin = "D:\\softWare\\TSBrowser\\TSBrowser.exe";//chrome启动文件路径
    private  static String chromedriver = "D:/software/chromedriver.exe";//chromedriver文件路径
    private volatile static WebDriver driver =null;

    public static WebDriver getInstance() {
        if (driver == null) {
            synchronized (WebDriverUtils.class) {
                /* 设定 chrome启动文件的位置, 若未设定则取默认安装目录的 chrome */
                System.setProperty("webdriver.chrome.bin", chromebin);
                /* 设定 chrome webdirver 的位置 ,若未设定则从path变量读取*/
                System.setProperty("webdriver.chrome.driver", chromedriver);
                ChromeOptions options = new ChromeOptions();
                /*设置无头模式*/
//                options.addArguments("--headless");
                options.setBinary(chromebin);
                if(driver == null) {
                    driver =new ChromeDriver(options);
                }
            }
        }
        return driver;
    }
}